package com.mooc.ppjoke;

import com.blankj.utilcode.util.LogUtils;
import com.bw.common.entity.RoomUserEntity;
import com.bw.common.mvvm.model.BaseModel;
import com.bw.network_sdk.RetrofitManager;
import com.bw.network_sdk.entity.BaseEntity;
import com.mooc.ppjoke.entity.IsLoginEntity;
import com.mooc.ppjoke.entity.LoginEntity;
import com.mooc.ppjoke.loginroom.LoginDao;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;

public class LoginModel extends BaseModel {

    public Observable<BaseEntity> requestUserEntity(LoginEntity loginEntity){
        Observable<RoomUserEntity> roomUserEntityObservable = RetrofitManager.getInstance()
                .getRetrofit()
                .create(ApiService.class)
                .requestUser(loginEntity.avatar,
                        loginEntity.description,
                        loginEntity.expires_time,
                        loginEntity.followCount,
                        loginEntity.likeCount,
                        loginEntity.name,
                        loginEntity.qqOpenId,
                        loginEntity.topCommentCount);
        return checkNetWork(roomUserEntityObservable);
    }

    public Observable<BaseEntity> addLogin(LoginDao dao, RoomUserEntity.InsertUserValuesEntity entity){
        Observable<IsLoginEntity> observable = new Observable<IsLoginEntity>() {
            @Override
            protected void subscribeActual(Observer<? super IsLoginEntity> observer) {
                dao.loginInsert(entity);
                IsLoginEntity isLoginEntity = new IsLoginEntity();
                isLoginEntity.status = 200;
                isLoginEntity.message = "登录成功";
                observer.onNext(isLoginEntity);
                LogUtils.e("执行");
                observer.onComplete();
            }
        };
        return checkNetWork(observable);
    }
}
